import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: syyyy
 * Date: 2025-07-24
 * Time: 17:19
 */
public class Test5 {
    public static void swap(int[] nums,int index,int len){
        for (int i = index; i < len-1; i++) {
            nums[i]=nums[i+1];
        }
    }
    public static void func(int[] nums,int val,int len){
        while(true) {
            boolean isVal=false;
            for (int i = 0; i < len; i++) {
                if (nums[i] == val) {
                    int index = i;
                    swap(nums, index, len);
                    len--;
                    isVal=true;
                }
            }
            if(isVal==false){
                break;
            }
        }
        System.out.println(len);
        System.out.println(Arrays.toString(nums));
    }
    public static void main(String[] args) {
        int[] nums={0,1,2,2,3,0,4,2};
        int len=nums.length;
        int val=2;
        func(nums,val,len);
    }
}
